﻿package com.gengine.core
{
    import flash.utils.*;

    public class MapFrameUtil extends Object
    {
        private static var _dicMapFrame:Dictionary = new Dictionary();
        private static var _dicMapTotalTime:Dictionary = new Dictionary();
        private static var _currentMapId:int;
        private static var _currentRenderCount:int;
        private static var _currentMapStartTime:int;
        private static var _isStop:Boolean = false;

        public function MapFrameUtil()
        {
            return;
        }// end function

        public static function start() : void
        {
            _isStop = false;
            _currentMapStartTime = getTimer();
            _currentRenderCount = 0;
            return;
        }// end function

        public static function stop() : void
        {
            checkOut();
            _isStop = true;
            return;
        }// end function

        public static function startMapId(param1:int) : void
        {
            changeMapId(param1);
            return;
        }// end function

        public static function changeMapId(param1:int) : void
        {
            checkOut();
            _currentMapId = param1;
            return;
        }// end function

        public static function checkOut() : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (_isStop)
            {
                return;
            }
            var _loc_1:* = getTimer();
            if (_currentMapId)
            {
                _loc_2 = _dicMapFrame[_currentMapId];
                _loc_2 = _loc_2 + _currentRenderCount;
                _dicMapFrame[_currentMapId] = _loc_2;
                _loc_3 = _dicMapTotalTime[_currentMapId];
                _loc_3 = _loc_3 + (_loc_1 - _currentMapStartTime);
                _dicMapTotalTime[_currentMapId] = _loc_3;
            }
            _currentMapStartTime = _loc_1;
            _currentRenderCount = 0;
            return;
        }// end function

        public static function render() : void
        {
            if (!_isStop && _currentMapId)
            {
                var _loc_2:* = _currentRenderCount + 1;
                _currentRenderCount = _loc_2;
            }
            return;
        }// end function

        public static function getMapFrame(param1:int) : int
        {
            var _loc_2:int = 0;
            checkOut();
            if (_dicMapTotalTime[param1])
            {
                _loc_2 = _dicMapTotalTime[param1] * 1 / _dicMapFrame[param1];
                return int(1000 / _loc_2);
            }
            return 60;
        }// end function

    }
}
